package com.yupi.yupicturebackend.exception;

public class ThrowUtils {

    /**
     * 条件成立刨出异常
     *
     * @param condition         条件
     * @param runtimeException  异常
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException){
        if (condition){
            throw runtimeException;
        }
    }

    /**
     * 根据条件和错误码刨出异常
     * @param condition 条件
     * @param errorCode 错误码
     */
    public static void throwIf(boolean condition, ErrorCode errorCode){
        throwIf(condition, new BusinessException(errorCode));
    }

    /**
     * 根据条件、错误码和消息刨出异常
     * @param condition 条件
     * @param errorCode 错误码
     * @param message   消息
     */
    public static void throwIf(boolean condition, ErrorCode errorCode, String message){
        throwIf(condition, new BusinessException(errorCode.getCode(), message));
    }
}
